package com.hyh.admin.esconfig;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PreDestroy;

@Configuration
public class EsClientConfig {

    private RestHighLevelClient client;

    @Bean
    public RestHighLevelClient client() {
        this.client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("121.40.59.140", 9200, "http"))
        );
        return this.client;
    }

    @PreDestroy
    public void close() throws Exception {
        if (client != null) {
            client.close();
        }
    }
}

